#pragma once

#include <vector>
#include <pthread.h>

class TConnectionManager {
public:
    typedef std::vector<int>    TConnectionQueue;
    static const int            KStopSignal =   -1;

    TConnectionManager()
    : UnservedMaxSize(0)
    , UnservedConnections()
    , ConnectionQueueMutex(NULL)
    , IsHaveNewMessage(NULL)
    , IsStoped(false)
    {}

    bool Init(unsigned int unservedMaxSize);
    ~TConnectionManager();

    bool AddConnection(int connectionId);
    int  GetUnservedConection();
    void Stop();
private:
    //does not copy
    TConnectionManager(TConnectionManager& another);
    TConnectionManager& operator = (TConnectionManager& another);

private:
    unsigned int        UnservedMaxSize;
    TConnectionQueue    UnservedConnections;
    pthread_mutex_t*    ConnectionQueueMutex;
    pthread_cond_t*     IsHaveNewMessage;
    bool                IsStoped;
};



